package com.lc1993929.mr.flow;

import lombok.*;
import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * Created by LiuChang on 2017/11/6/006.
 * <p>
 * hadoop中的数据会频繁的被序列化和反序列化
 * 所以定义的类型：FlowBean必须要实现hadoop的序列化接口
 */
@Data
@AllArgsConstructor
@RequiredArgsConstructor
@NoArgsConstructor
public class FlowBean implements Writable {
    @NonNull
    private Long upFlow;
    @NonNull
    private Long dFlow;
    private Long sumFlow;

    /**
     * hadoop序列化框架在反序列化时调用的方法
     *
     * @param out
     * @throws IOException
     */
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(upFlow);
        out.writeLong(dFlow);
        out.writeLong(sumFlow);
    }

    /**
     * hadoop序列化框架在序列化时调用的方法
     *
     * @param in
     * @throws IOException
     */
    @Override
    public void readFields(DataInput in) throws IOException {
        this.upFlow = in.readLong();
        this.dFlow = in.readLong();
        this.sumFlow = in.readLong();
    }
}
